package cn.parus.dynamicRouter.controller;

import cn.parus.dynamicRouter.service.JwtService;
import cn.parus.commons.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Title: JWTController
 * @Author 潘春兰
 * @Package cn.parus.auth.controller
 * @Date 2025/3/23 14:58
 * @description: TODO JWT加密和解密接口
 * @Version:
 */
@RestController
@RequestMapping("/api-jwt")
public class JWTController {

    @Autowired
    private JwtService jwtService;

    /**
     * 使用jwt生成token
     *
     * @param jwtContent
     * @return
     */
    @PostMapping("/generateJwt")
    public Result generateJwt(@RequestBody Map<String, Object> jwtContent) {
        Map<String, Object> token = jwtService.createJwt(jwtContent);
        return Result.success(token);
    }

    /**
     * 使用jwt解析token
     *
     * @param token
     * @return
     */
    @GetMapping("/parseJwt")
    public Result parseJwt(String token) {
        Map<String, Object> tokenData = jwtService.parseJwt(token);
        return Result.success(tokenData);
    }

}
